from services.TaskManager import Task
from queue import PriorityQueue
# from multiprocessing import Pool, Process


class TasksConsumer(object):
    def __init__(self):
        self.priorityQueue = PriorityQueue()
        self.currentTask = None
        # self.processPool = Pool(processes=3)

    def addTask(self, task: Task):
        self.priorityQueue.put_nowait(task)
        return self

    def _consumer_Task(self):
        print("consumer_task")
        while not self.priorityQueue.empty():
                task = self.priorityQueue.get_nowait()
                task.execute()  #todo
                # self.processPool.apply_async(task.execute)

    def executeNowait(self):
        print("执行 process 单独执行")
        self._consumer_Task()
